<!-- 自定义标准图表 设置百分百宽度 通过平台组件来适配尺寸 可以替换数据以及设置高级属性自定义扩展 详细查看组件示例.txt
  注:如需设置图片存放文件夹名称需应与当前文件名一致(1并在aircim.webpack.build.component.config.js配置需要打包的文件 2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中)-->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <div
        class="service-efficiency-box animate__animated"
        :class="dynamicClassName"
        style="width: 460px;height: 921px;"
        :id="dynamicChildName()"
    >
      <h1 class="h1_title">
        <span>网办能力</span>
      </h1>
      <ul class="net-list">
        <li class="net-item">
          <span>I级网办</span>
          <span class="item-content"><em>268</em>个</span>
          <span class="item-per"><em>23,40</em>%</span>
        </li>
        <li class="net-item">
          <span>I级网办</span>
          <span class="item-content"><em>268</em>个</span>
          <span class="item-per"><em>23,40</em>%</span>
        </li>
        <li class="net-item">
          <span>I级网办</span>
          <span class="item-content"><em>268</em>个</span>
          <span class="item-per"><em>23,40</em>%</span>
        </li>
        <li class="net-item">
          <span>I级网办</span>
          <span class="item-content"><em>268</em>个</span>
          <span class="item-per"><em>23,40</em>%</span>
        </li>
      </ul>
      <h2 class="h2_title"><span>全程网办情况</span></h2>
      <div class="show-panel panel1">
        <div class="show-panel-item">
          <div class="show-panel-item-title">全程网办率</div>
          <div class="show-panel-item-content">
            <em>84.20</em>%
          </div>
        </div>
        <div class="show-panel-item">
          <div class="show-panel-item-title">全程网办率同比</div>
          <div class="show-panel-item-content down">
            <em>2.28</em>%
          </div>
        </div>
      </div>
      <div class="common-table" style="margin-bottom: 27px">
        <p class="table-name">
          <span class="table-index">序号</span>
          <span class="table-flex">部门名称</span>
          <span class="table-1-4">全程网办率</span>
        </p>
        <TableScroll :container-height="120" :speed="10">
          <ul class="table-bd">
            <li class="table-bd-item">
              <span class="table-index">01</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">02</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">03</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">04</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">05</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
              </span>
            </li>
          </ul>
        </TableScroll>
      </div>

      <h2 class="h2_title"><span>可掌办情况</span></h2>
      <div class="show-panel panel2">
        <div class="show-panel-item">
          <div class="show-panel-item-title">可掌办率</div>
          <div class="show-panel-item-content">
            <em>84.20</em>%
          </div>
        </div>
        <div class="show-panel-item">
          <div class="show-panel-item-title">可掌办率同比</div>
          <div class="show-panel-item-content down">
            <em>2.28</em>%
          </div>
        </div>
      </div>
      <div class="common-table">
        <p class="table-name">
          <span class="table-index">序号</span>
          <span class="table-flex">部门名称</span>
          <span class="table-1-4">可掌办率</span>
        </p>
        <TableScroll :container-height="120" :speed="10">
          <ul class="table-bd">
            <li class="table-bd-item">
              <span class="table-index">01</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">02</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">03</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">04</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
                </span>
            </li>
            <li class="table-bd-item">
              <span class="table-index">05</span>
              <span class="table-flex">部门名称字段内容字段内容</span>
              <span class="table-1-4">
                  <p class="num"><em>2340</em>%</p>
              </span>
            </li>
          </ul>
        </TableScroll>
      </div>
    </div>
  </div>
</template>
<script>
//引入封装方法
import encapsulation from "../../utils/aircimGird";
import TableScroll from "../elements/TableScroll.vue"
export default {
  //混入封装方法
  mixins: [encapsulation],
  components: {
    TableScroll
  },
  data: function() {
    return {
      resizeObserver: null,
      //动态Id
      timestamp: null,

    };
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },
  methods: {
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
          `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
}

.service-efficiency-box {
  position: absolute;
  padding: 0 20px;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: left top;
  background-image: url(../../../thumbnail/backImg/new-border-mini-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #fff;
}
.net{
  &-list{
    width: 100%;
    height: 118px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 27px 0 25px 0;
  }
  &-item{
    width: 78px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: url("../../static/assets/ServiceNetManage/icon.png") no-repeat center center;
    background-size: 78px 59px;
    font-family: "Source Han Sans CN";
    color: #FFF;
    font-size: 14px;
    font-weight: 400;
    .item-content{
      color: #96BEE0;
      em{
        margin-right: 4px;
        color: #0FF;
        text-align: center;
        font-family: D-DIN;
        font-size: 20px;
        font-weight: 700;
      }
    }
    .item-per{
      margin-top: auto;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 84px;
      height: 26px;
      color: #96BEE0;
      background: url("../../static/assets/ServiceNetManage/bottom.png") no-repeat center center;
      background-size: cover;
      em{
        margin-right: 4px;
        color: #0FF;
        text-align: center;
        font-family: D-DIN;
        font-size: 20px;
        font-weight: 700;
      }
    }
  }

}
.panel1{
  margin: 11px 0 12px 0;
  background-image: url("../../static/assets/ServiceNetManage/pc_bg.png");
}
.panel2{
  margin: 11px 0 12px 0;
  background-image: url("../../static/assets/ServiceNetManage/phone_bg.png");
}

</style>
